package com.dwx.gmall.product.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.dwx.gmall.common.result.Result;
import com.dwx.gmall.model.product.BaseAttrInfo;
import com.dwx.gmall.model.product.BaseSaleAttr;
import com.dwx.gmall.model.product.SpuInfo;
import com.dwx.gmall.product.service.BaseSaleAttrService;
import com.dwx.gmall.product.service.SpuInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/admin/product")
public class SpuInfoController {

    @Autowired
    SpuInfoService spuInfoService;

    @Autowired
    BaseSaleAttrService baseSaleAttrService;
    @GetMapping("/{page}/{limit}")
    public Result<Page<SpuInfo>> pageSpuInfo(
            @PathVariable(value = "page") Long page,
            @PathVariable(value = "limit") Long limit,
            @RequestParam(value = "category3Id") Long category3Id
    ){
        Page<SpuInfo> spuInfoPage=new Page<>(page,limit);
        QueryWrapper<SpuInfo> queryWrapper=new QueryWrapper<>();
        queryWrapper.eq("category3_id",category3Id);
        spuInfoService.page(spuInfoPage,queryWrapper);
        return Result.ok(spuInfoPage);
    }

    @GetMapping("/baseSaleAttrList")
    public Result<List<BaseSaleAttr>> baseSaleAttrList(){
        List<BaseSaleAttr> list = baseSaleAttrService.list();
        return Result.ok(list);
    }

    @PostMapping("/saveSpuInfo")
    public Result saveSpuInfo(@RequestBody SpuInfo spuInfo){
        boolean b=spuInfoService.saveSpuInfo(spuInfo);
        return Result.ok();
    }

}
